package _2022.hot100._11_盛最多水的容器;

/**
 * @author： YHSimon
 * @date： 2022-03-31 14:43
 */
public class Solution {


    //4ms
    public int maxArea2(int[] height){
        int res=0;
        int left=0,right=height.length-1;
        while(left<right){
            int tmp=Math.min(height[left],height[right])*(right-left);
            res=Math.max(res,tmp);
            if(height[left]<=height[right]){
                left++;
            }else{
                right--;
            }
        }
        return res;
    }
    //超时
    public int maxArea(int[] height){
        int res=0;
        for(int i=0;i<height.length;i++){
            for(int j=i+1;j<height.length;j++){
                int tmp=Math.min(height[i],height[j])*(j-i);
                res=Math.max(res, tmp);
            }
        }
        return res;
    }

    public static void main(String[] args) {
        Solution s = new Solution();
        System.out.println(s.maxArea(new int[]{1,8,6,2,5,4,8,3,7}));
    }
}
